--
-- Author: shunguo.chen
-- Date: 2017-09-11 11:56:12
--
-- LoginSelectRender	参数选择

local ClassRef = app.mvc.createRenderClass(...)

--data = {index=, datas=, name=}
function ClassRef.create(data, node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.LoginZoneNode1))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)

	self:setContentSize(self._ui.Panel:getContentSize())

	-- btns
	self._ui.Button_1:setPressedActionEnabled(false)
	self._ui.Button_2:setPressedActionEnabled(false)
	self._ui.Button_1:addClickEventListener(function()
		self._index = self._index - 1
		if self._index <= 0 then
			self._index = #self._data.datas
		end
		self:setName()
		executeFunc(self._onBtnClick, self._data.datas[self._index])
	end)
	self._ui.Button_2:addClickEventListener(function()
		self._index = self._index + 1
		if self._index > #self._data.datas then
			self._index = 1
		end
		self:setName()
		executeFunc(self._onBtnClick, self._data.datas[self._index])
	end)

	self:refresh()
end

function ClassRef:refresh()
	if self._data then
		self._index = self._data.index or 1
		self:setName()
	end
end

function ClassRef:onBtnClick(cb)
	self._onBtnClick = cb
end

function ClassRef:getIndex()
	return self._index
end

function ClassRef:setDatas(datas)
	self._data.datas = datas
end

function ClassRef:setName()
	self._ui.Text:setString(self._data.name .. self._index)
end

return ClassRef